
import axios from '@/utils/http';

const SET_USER_INFO = 'SET_USER_INFO';

const initState = {
  info: {},
};

const getters = {};
const actions = {
  login(ctx, { username, password }) {
    return axios.post('/user/login', {
      username, password,
    })
      .then(({ data }) => {
        ctx.commit(SET_USER_INFO, data);
      });
  },
  getUserInfo(ctx) {
    return axios.get('/user/userinfo')
      .then(({ data }) => {
        ctx.commit(SET_USER_INFO, data);
      });
  },
};

const mutations = {
  [SET_USER_INFO](state, deploy) {
    state.info = deploy;
  },
};

export default {
  state: initState,
  getters,
  actions,
  mutations,
};
